#include <iostream>
#include <vector>

using namespace std;

// https://leetcode.cn/problems/course-schedule/description/
// 

class Solution
{
public:
    bool dfs(vector<int> &color, vector<vector<int>> &graph, int curIndex)
    {
        color[curIndex] = 1;
        if (graph[curIndex].size() > 0)
        {
            for (auto it : graph[curIndex])
            {
                if (color[it] == 1 || color[it] == 0 && dfs(color, graph, it))
                {
                    return true;
                }
            }
        }

        color[curIndex] = 2;
        return false;
    }
    bool canFinish(int numCourses, vector<vector<int>> &prerequisites)
    {
        vector<int> color(numCourses);
        vector<vector<int>> graph(numCourses);
        for (auto it : prerequisites)
        {
            graph[it[1]].push_back(it[0]);
        }
        for (int i = 0; i < numCourses; i++)
        {
            if (color[i] == 0 && dfs(color, graph, i))
            {
                return false;
            }
        }
        return true;
    }
};

int main()
{
    Solution solution{};
    vector<vector<int>> graph{{1, 0}};
    cout << solution.canFinish(2, graph) << endl;
    return 0;
}
